import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_app/router/route.dart';
import 'package:flutter_app/router/switch_animation.dart';
import 'package:flutter_app/util/ToastUtil.dart';
import 'package:flutter_app/view/web_view_page.dart';
///路由封装器
class XRouter {
  static FluroRouter ?router;

  static void init() {
    router = FluroRouter();
    configureRoutes(router);
  }

  static void configureRoutes(FluroRouter ?router) {
    router?.notFoundHandler = Handler(
        handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
      print("route is not find !");
      return null;
    });

    router?.define('/web', handler: webViewPageHand);
  }

  static void goto(BuildContext context, String pageName) {
    var value = RouteMap.routes[pageName];
    if (value == null) {
      ToastUtil.toastShort("没有设置页面");
    } else {
      Navigator.push(context, SlidePageRoute(routeName: pageName));
    }
  }

  static void gotoWidget(BuildContext context, Widget widget) {
    if (widget == null) {
      ToastUtil.toastShort("暂未开放！");
    } else {
      Navigator.push(context, SlidePageRoute(widget: widget));
    }
  }
}

Handler webViewPageHand = Handler(
    handlerFunc: (BuildContext ?context, Map<String, List<String>> params) {
  String ?title = params['title']?.first;
  String ?url = params['url']?.first;
  return WebViewPage(url!, title!);
});
